package com.lanou3g.dllo.baidumusic.musiclibrary.recommend.allsingerdetail;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.base.MyApp;
import com.lanou3g.dllo.baidumusic.tools.SingleVolley;

import java.util.List;

/**
 * Created by dllo on 16/6/27.
 */
public class AllSingerDetailAdapter extends BaseAdapter {
    private AllSingerDetailBean allSingerDetailBean;
    private Context context;
    private List<AllSingerDetailBean.ArtistBean> list;

    public AllSingerDetailAdapter(Context context) {
        this.context = context;
    }

    public void setAllSingerDetailBean(AllSingerDetailBean allSingerDetailBean) {
        this.allSingerDetailBean = allSingerDetailBean;
        list = allSingerDetailBean.getArtist();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_allsingerdetail, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SingleVolley.getSingleVolley(context).getImageLoader().get(list
                .get(position).getAvatar_big(), ImageLoader.getImageListener(holder.allSingerDetailIcon, R.mipmap.ic_launcher, R.mipmap.ic_launcher));
        holder.allSingerDetailSingerDetail.setText(list.get(position).getName());
        return convertView;
    }

    class ViewHolder {

        ImageView allSingerDetailIcon;
        TextView allSingerDetailSingerDetail;

        public ViewHolder(View view) {
            allSingerDetailIcon = (ImageView) view.findViewById(R.id.allsingerdetail_icon);
            allSingerDetailSingerDetail = (TextView) view.findViewById(R.id.allsingerdetail_singerdetail);

        }
    }
}
